# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer:
pkgname=mautrix-telegram
pkgver=0.9.0
pkgrel=5
pkgdesc="A Matrix-Telegram hybrid puppeting/relaybot bridge"
url="https://github.com/tulir/mautrix-telegram"
arch="noarch"
license="AGPL-3.0-or-later"
depends="
	py3-aiohttp
	py3-alembic
	py3-commonmark
	py3-magic
	py3-mautrix>~0.8.3
	py3-ruamel.yaml
	py3-sqlalchemy
	py3-telethon>~1.17
	py3-telethon-session-sqlalchemy
	python3
	"
makedepends="
	py3-pytest-runner
	py3-setuptools
	"
checkdepends="
	py3-pytest
	py3-pytest-asyncio
	py3-pytest-mock
	py3-pytest-runner
	"
install="$pkgname.pre-install $pkgname.post-upgrade"
subpackages="$pkgname-openrc"
source="https://github.com/tulir/mautrix-telegram/archive/v$pkgver/mautrix-telegram-v$pkgver.tar.gz
	mautrix-telegram.initd
	mautrix-telegram.confd
	default-log-dir.patch
	"
options="!check" # Broken for now

build() {
	python3 setup.py build
}

check() {
	pytest
}

package() {
	python3 setup.py install --prefix=/usr --root="$pkgdir"

	# Remove installed tests
	local _site_packages=$(python3 -c "import site; print(site.getsitepackages()[0])")
	rm -r "$pkgdir/$_site_packages"/tests/

	install -Dm644 mautrix_telegram/example-config.yaml "$pkgdir"/etc/mautrix-telegram/example-config.yaml
	install -Dm755 "$srcdir"/mautrix-telegram.initd "$pkgdir"/etc/init.d/mautrix-telegram
	install -Dm644 "$srcdir"/mautrix-telegram.confd "$pkgdir"/etc/conf.d/mautrix-telegram

	mkdir -p "$pkgdir"/usr/share/mautrix-telegram
	mv \
		"$pkgdir"/usr/alembic \
		"$pkgdir"/usr/alembic.ini \
		"$pkgdir"/usr/share/mautrix-telegram/
}
sha512sums="16622cf9f1624c8641fbda9a47e34bc78d08f068cf6c6715fb8da8d2bad19e02fc161b8b246623400831f25d466fa40ae14115bae716997ed83e8ba683e30c76  mautrix-telegram-v0.9.0.tar.gz
ee0c29822abf213acf2a63205bdb3fca845c916682f1f7dadf17f443fba8191844a0ee9e0ca323e6de7d539e141f2df1b4457a7fbfbe8af607e3189809d23205  mautrix-telegram.initd
7b3c15dd2d0671c4c777bcf4f2e905d9a0b639a54828313ac9db1a9793fde3d092e92f18aa896bff94b9a81db3df74b3de65661c6879cb648d36f5cec2437df0  mautrix-telegram.confd
09e9afa45341927fc6085573aaa8a2b3816ad75b664d57ebd2e44cab2612f97972f022e66a4b98e5cd1c7421d257859ffa5333201f11a5666cdaa470b8618c03  default-log-dir.patch"
